﻿@*model winproject.Models.GlobalViewModel*@
@using winproject.Models;
@{
    ViewBag.Title = "Virus";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";

    int resCode = 0;
    VirusDetails oVirusEditDetail = null;
    if (ViewData != null && ViewData.Keys.Count()>0 && ViewData.Keys.Contains("resCode"))
    {
        resCode = Convert.ToInt32(ViewData["resCode"]);
    }
    if(resCode==250){
        oVirusEditDetail =(VirusDetails)ViewData["resData"];   
    }
    
}

@Styles.Render("~/Content/Vendors")
<link type="text/css" rel="stylesheet" href="~/Content/css/jquery-te-1.4.0.css">
<script type="text/javascript" src="~/Scripts/jquery-te-1.4.0.js" charset="utf-8"></script>
@Html.Partial("_LeftMenu")


<!-- content -->
<div class="col-md-10">
    
    <div class="row">
        <div class="panel panel-default bootstrap-admin-no-table-panel">
            <div class="panel-heading">
                <div class="text-muted bootstrap-admin-box-title">Virus > Details</div>
            </div>
            <div class="bootstrap-admin-no-table-panel-content bootstrap-admin-panel-content collapse in">
                <form id="frmVirus" action="~/Admin/VirusUpload"  method="post" enctype="multipart/form-data" >
                    @{
                        if (oVirusEditDetail != null && (oVirusEditDetail.nVirusId)>0){
                            <input type="hidden" id="txtVirusId" name="txtVirusId" value="@oVirusEditDetail.nVirusId" />
                        }
                          else{
                            <input type="hidden" id="txtVirusId" name="txtVirusId" value="0" />   
                        }
                     }
                <table width="100%"  cellpadding="5" class="table-striped">
                    <tr>
                        <td style="width:200px;vertical-align:top">
                            Enter Virus Name
                        </td>
                        <td style="width:20px;vertical-align:top">:</td>
                        <td>
                            @{
                                if(oVirusEditDetail!=null && !string.IsNullOrEmpty(oVirusEditDetail.sVirusName)){
                                    <input type="text" id="txtVirusName" name="txtVirusName" value="@oVirusEditDetail.sVirusName.Trim()"/>
                                }
                                else{
                                    <input type="text" id="txtVirusName" name="txtVirusName" />
                                }
                            }
                        </td>
                    </tr>
                    <tr>
                        <td style="width:200px;vertical-align:top">
                            Enter Virus Slug
                        </td>
                        <td style="width:20px;vertical-align:top">:</td>
                        <td>
                            @{
                                if (oVirusEditDetail != null && !string.IsNullOrEmpty(oVirusEditDetail.sVirusSlug))
                                {
                                    <input type="text" id="txtVirusSlug" name="txtVirusSlug" value="@oVirusEditDetail.sVirusSlug.Trim()"/>
                                }
                                else{
                                    <input type="text" id="txtVirusSlug" name="txtVirusSlug" />
                                }
                            }
                        </td>
                    </tr>
                    <tr>
                        <td style="width:200px;vertical-align:top" >
                            Description
                        </td>
                        <td style="width:20px;vertical-align:top">:</td>
                        <td style="vertical-align:top">
                            <textarea id="txtVirusDesc" name="txtVirusDesc" class="jqte-test">
                                 @{
                                    if (oVirusEditDetail != null && !string.IsNullOrEmpty(oVirusEditDetail.sVirusDescription))
                                    {
                                        @WebUtility.HtmlDecode(oVirusEditDetail.sVirusDescription)
                                    }
                                }
                            </textarea>

                        </td>
                    </tr>
                    <tr>
                        <td style="width:200px;vertical-align:top">
                            Select Virus Image
                        </td>
                        <td style="width:20px;vertical-align:top">:</td>
                        <td>
                            <input type="file" name="viruspic" id="viruspic" />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            &nbsp;
                        </td>
                        <td class="text-left">
                            @{
                                if (oVirusEditDetail != null && (oVirusEditDetail.nVirusId)>0){
                                    <button type="submit" id="cmdSave" name="cmdSave" value="Save">Save</button>
                                }
                                else{
                                    <button type="submit" id="cmdSave" name="cmdSave" value="Add">Add</button>
                                }
                            }
                            &nbsp; &nbsp;
                            <button type="button" id="cmdCancel" name="cmdSave" value="Cancel" onclick="window.location.href='@HttpContext.Current.Request.ApplicationPath/Admin/Virus'">Cancel</button>
                        </td>
                    </tr>
                </table>
                </form>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="panel panel-default bootstrap-admin-no-table-panel">
            <div class="panel-heading">
                <div class="text-muted bootstrap-admin-box-title">Virus Listing</div>
            </div>
            <div class="bootstrap-admin-no-table-panel-content bootstrap-admin-panel-content collapse in">
                <div class="row">
                    <div class="col-md-12">
                        <table width="100%" cellpadding="5" cellspacing="0" class="table-striped">
                            <thead>
                                <th>Sr.No</th>
                                <th>Virus Name</th>
                                <th>Slug</th>
                                <th>Image</th>
                                <th>Description</th>
                                <th>Actions</th>
                            </thead>
                            <tbody id="list_virsuinfo">
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>

<script type="text/html" id="tpl_virusinfo">
    <tr id="vinfo-{vid}-item">
        <td>
            {srno}
        </td>
        <td>
            {vname}
        </td>
        <td>
            {vslug}
        </td>
        <td>
            <img src="{vimg}" height="35" alt="{vname}" title="{vname}"/>
        </td>
        <td>
            {vdesc}
        </td>
        <td>
            <a href="javascript:void(0)"  onclick="return editItem({vid});">Edit</a>
            &nbsp;/&nbsp; 
            <a href="javascript:void(0)" class="del-action"  data-toggle="modal" data-target="#myModal"  onclick="return deleteItem({vid},'virus-item');">Delete</a>
        </td>
    </tr>
</script>



<script>
    var oMycontentLoader = new MyContentLoader();

    //Declarations
    var virusGridListGlobal = [];
    
    function VirusDetails(){
        this.nVirusId=0;
        this.sVirusName ="";
        this.sVirusSlug ="";
        this.sVirusDescription="";
        this.sVirusImagePath="";
        this.nVirusStatus=0;
    }

    function editItem(itemid) {
        if (!isNaN(itemid) && parseInt(itemid) > 0) {
            var oVirusdetail = new VirusDetails();
            oVirusdetail.nVirusId = itemid;
            $("#txtVirusId").val(itemid);
            $("#frmVirus").attr("action", approotpath + "Admin/Virus");
            $("#frmVirus").submit();
        }
    }
    function deleteItem(itemid, targetitem) {
        
        if (confirm("Are you sure want to delete?")) {
            switch (targetitem) {
                case 'virus-item':
                    deleteVirusItem(itemid);
                    break;
            }
            //var callback = function () {
            //    switch (targetitem) {
            //        case 'virus-item':
            //            deleteVirusItem(itemid);
            //            break;
            //    }
            //};
        }

        

        
    }
    function deleteTargetItem(itemid, targetitem) {
        switch (targetitem) {
            case 'virus-item':
                deleteVirusItem(itemid);
                break;
        }
    }

    function deleteVirusItem(itemid) {
        if (!isNaN(itemid) && parseInt(itemid) > 0) {
            var oVirusdetail = new VirusDetails();
            oVirusdetail.nVirusId = itemid;


            $(document).ready(function () {
                $.ajax(approotpath + "Admin/DeleteVirus", {
                    data: oVirusdetail,
                    type: "POST",
                    dataType: 'json',
                    success: function (data) {
                        var dataJson = data;//$.parseJSON(data);
                        if (parseInt(dataJson.errCode) == 250) {
                            if (document.getElementById("vinfo-" + itemid + "-item")) {
                                $("#vinfo-" + itemid + "-item").remove();
                                if ($("#list_virsuinfo").find("tr").length <= 0) {
                                    $("#list_virsuinfo").append(oMycontentLoader.noRecordExist(6, "No More Records Exists"));
                                }
                                alert("Item removed");
                            }
                        }
                    }
                });
            });
        }
    }

    //get virus detail list on load time
    $(document).ready(function () {
        oMycontentLoader.showLoader("list_virsuinfo", 6, true);
        $.ajax(approotpath + "Admin/GetVirusDetailJson", {
            data: {},
            type: "GET",
            dataType: 'json',
            success: function (data) {
                var dataJson = $.parseJSON(data.msgJson);
                makeVirusGrid(dataJson);
                //self.categories(mappedCategories);
            },
            error: function (jqXHR, status, err) {
                console.log("Error raised: " + err);
                $("#list_virsuinfo").append(noRecordExist(6, "Oop's Something went wrong..."));
            },
            complete: function (jqXHR, status) {
                oMycontentLoader.hideLoader(oMycontentLoader.LastAccessedContainerId);
            }
        });
    });
    

    //getVirusDetail():: fetches virus details
    function getVirusDetail() {
        $.getJSON(approotpath + "Admin/GetVirusDetailJson", function (response) {
            //alert(catResponse.errCode);
            if (response.errCode == 250) {
                return $.parseJSON(response.msgJson);
            }
            else {
                return [];
            }

        });
    }
    //makeVirusGrid():: Lists virus details
    function makeVirusGrid(virusGridList) {

        if (virusGridList.length > 0) {
            virusGridListGlobal.push(virusGridList);
            if (document.getElementById("list_virsuinfo")) {
                var virusinfo_template = $("#tpl_virusinfo").html();
                var vcount = 0;
                var vdesc = "";
                for (vcount = 0; vcount < virusGridList.length; vcount++) {
                    vdesc = htmlDecode(virusGridList[vcount].sVirusDescription);
                    $("#list_virsuinfo").append(virusinfo_template.replace(/{srno}/g, (vcount + 1)).replace(/{vname}/g, virusGridList[vcount].sVirusName).replace(/{vslug}/g, virusGridList[vcount].sVirusSlug).replace(/{vimg}/g, getAppPath(virusGridList[vcount].sVirusImagePath)).replace(/{vdesc}/g, vdesc).replace(/{vid}/g, virusGridList[vcount].nVirusId));
                }
                
            }
        }
        var ignoreRows = 0;
        if (document.getElementById("list_virsuinfo" + "_loader")) {
            ignoreRows = 1;
        }
        if ($("#list_virsuinfo").find("tr").length <= 0) {
            $("#list_virsuinfo").append(oMycontentLoader.noRecordExist(6, "No More Records Exists"));
        }
    }


    $('.jqte-test').jqte();
	
	// settings of status
	var jqteStatus = true;
	$(".status").click(function()
	{
		jqteStatus = jqteStatus ? false : true;
		$('.jqte-test').jqte({"status" : jqteStatus})
	});

	
</script>
